﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace UILibrary
{
    /// <summary>
    /// CircularBoardItem.xaml 的交互逻辑
    /// </summary>
    public partial class CircularBoardItem : UserControl
    {
        public CircularBoardItem()
        {
            InitializeComponent();
            this.DataContext = this;
        }

        public double RotateAngle
        {
            get { return (double)GetValue(RotateAngleProperty); }
            set { SetValue(RotateAngleProperty, value); }
        }

        // Using a DependencyProperty as the backing store for RotateAngle.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty RotateAngleProperty =
            DependencyProperty.Register("RotateAngle", typeof(double), typeof(CircularBoardItem), new PropertyMetadata(0.0));



        public int Index
        {
            get { return (int)GetValue(IndexProperty); }
            set { SetValue(IndexProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Index.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IndexProperty =
            DependencyProperty.Register("Index", typeof(int), typeof(CircularBoardItem), new PropertyMetadata(0, PropertyChangedCallback));


        /// <summary>
        /// 角度
        /// </summary>
        public double Angle
        {
            get { return (double)GetValue(AngleProperty); }
            set { 
                SetValue(AngleProperty, value); 
            }
        }

        // Using a DependencyProperty as the backing store for Angle.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty AngleProperty =
            DependencyProperty.Register("Angle", typeof(double), typeof(CircularBoardItem), new PropertyMetadata(15.0, PropertyChangedCallback));


        /// <summary>
        /// 间距角度
        /// </summary>
        public double Space
        {
            get { return (double)GetValue(SpaceProperty); }
            set { 
                SetValue(SpaceProperty, value); 
            }
        }

        // Using a DependencyProperty as the backing store for Space.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty SpaceProperty =
            DependencyProperty.Register("Space", typeof(double), typeof(CircularBoardItem), new PropertyMetadata(0.0));


        /// <summary>
        /// 外半径
        /// </summary>
        public double RadiusOuter
        {
            get { return (double)GetValue(RadiusOuterProperty); }
            set { 
                SetValue(RadiusOuterProperty, value); 
            }
        }

        // Using a DependencyProperty as the backing store for RadiusOuter.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty RadiusOuterProperty =
            DependencyProperty.Register("RadiusOuter", typeof(double), typeof(CircularBoardItem), new PropertyMetadata(100.0, PropertyChangedCallback));


        /// <summary>
        /// 内半径
        /// </summary>
        public double RadiusInner
        {
            get { return (double)GetValue(RadiusInnerProperty); }
            set { 
                SetValue(RadiusInnerProperty, value); 
            }
        }

        // Using a DependencyProperty as the backing store for RadiusInner.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty RadiusInnerProperty =
            DependencyProperty.Register("RadiusInner", typeof(double), typeof(CircularBoardItem), new PropertyMetadata(0.0, PropertyChangedCallback));


        public static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var item = (CircularBoardItem)d;
            if (item != null)
            {
                item.RotateAngle = item.Index * item.Angle;
            }
        }
    }

    public class ConverterAngleBack : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return -(double)value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    public class ConverterDoubleHalf : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (double)value/2;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
